package com.lianrui.app.goods.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.lianrui.app.goods.dao.IProductDao;
import com.lianrui.app.goods.domain.Product;
import com.lianrui.app.goods.service.IProductSerivce;
import com.lianrui.app.goods.vos.ProductPage;
import com.lianrui.app.goods.vos.SpecVo;
import com.lianrui.commons.exception.BusinessException;
import com.lianrui.core.AbstractService;
import com.lianrui.core.IDao;

@Service("productService")
public class ProductSerivce
        extends AbstractService<ProductPage, Product, Integer>
        implements IProductSerivce {

    private static final long serialVersionUID = 1L;

    private static final Logger LOGGER = LoggerFactory
            .getLogger(ProductSerivce.class);

    @Resource
    IProductDao productDao;

    @Override
    public IDao<ProductPage, Product, Integer> getDao()
            throws BusinessException {
        return this.productDao;
    }

    @Override
    protected Logger getLogger() {
        return LOGGER;
    }

    /**
     * 
     * @Title: delete
     * @Description: 删除产品关联的表内容
     * @param id
     * @throws BusinessException
     * @see com.lianrui.core.AbstractService#delete(java.lang.Object[])
     */
    @Override
    public void delete(Integer... id) throws BusinessException {
        this.productDao.deleteGoodsSpec(id);// 删除关联的规则信息
        this.productDao.deleteGoodsLVPrice(id);// 删除关联的会员价格信息
        this.productDao.delete(id);// 删除产品
    }

    /**
     * 
     * @Title: getProductBygoodsId
     * @Description: 依据参数（商品ID）获取产品列表
     * @param id
     * @return 商品相关的产品列表
     * @throws BusinessException
     * @see com.lianrui.app.goods.service.IProductSerivce#getProductBygoodsId(java.lang.Integer)
     */
    @Override
    public List<Product> getProductBygoodsId(Integer id)
            throws BusinessException {
        return this.productDao.getProductBygoodsId(id);
    }

    @Override
    public List<SpecVo> getSpecs(Integer goodsId) throws BusinessException {
        return this.productDao.getSpecs(goodsId);
    }
}
